package com.bank.ui;

import com.bank.ui.CustomerLoginUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class IdentitySelectionUI extends JFrame {
    private final JComboBox<String> identityComboBox;
    private final JButton enterButton;

    public IdentitySelectionUI() {
        setTitle("身份选择");
        setSize(300, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 创建主面板
        JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        // 创建表单面板
        JPanel formPanel = new JPanel(new GridLayout(1, 2, 10, 10)); // 修改为1行2列

        // 身份选择
        formPanel.add(new JLabel("请选择身份:"));
        identityComboBox = new JComboBox<>(new String[]{"客户", "管理员"});
        formPanel.add(identityComboBox);

        mainPanel.add(formPanel, BorderLayout.CENTER);

        // 创建按钮面板
        enterButton = new JButton("进入");
        enterButton.addActionListener(this::enter);
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); // 使用FlowLayout使按钮并排
        buttonPanel.add(enterButton);

        mainPanel.add(buttonPanel, BorderLayout.SOUTH);

        setContentPane(mainPanel);
    }

    private void enter(ActionEvent e) {
        String identity = (String) identityComboBox.getSelectedItem();
        if ("客户".equals(identity)) {
            // 打开客户登录界面
            CustomerLoginUI customerLoginUI = new CustomerLoginUI();
            customerLoginUI.setVisible(true);
            dispose(); // 关闭当前窗口
        } else if ("管理员".equals(identity)) {
            // 打开管理员登录界面
            AdminLoginUI adminLoginUI = new AdminLoginUI();
            adminLoginUI.setVisible(true);
            dispose(); // 关闭当前窗口
        }
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(() -> {
            IdentitySelectionUI identitySelectionUI = new IdentitySelectionUI();
            identitySelectionUI.setVisible(true);
        });
    }
}